package com.cyq.day17.Demo2;

import java.util.Arrays;
import java.util.Objects;

public class Commodity {
    String name;
    double weight;
    double price;
    String[] partsProducer;
    int partsNum;

    public Commodity() {
    }

    public Commodity(String name, double weight, double price, String[] partsProducer, int partsNum) {
        this.name = name;
        this.weight = weight;
        this.price = price;
        this.partsProducer = partsProducer;
        this.partsNum = partsNum;
    }

    @Override
    public String toString() {
        return "Commodity{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                ", price=" + price +
                ", partsProducer=" + Arrays.toString(partsProducer) +
                ", partsNum=" + partsNum +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Commodity commodity = (Commodity) o;
        return Double.compare(commodity.weight, weight) == 0 &&
                Double.compare(commodity.price, price) == 0 &&
                partsNum == commodity.partsNum &&
                Objects.equals(name, commodity.name) &&
                Arrays.equals(partsProducer, commodity.partsProducer);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(name, weight, price, partsNum);
        result = 31 * result + Arrays.hashCode(partsProducer);
        return result;
    }
}
